package soft.edu.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import soft.edu.common.ServerResponse;
import soft.edu.dao.SchUniversityMapper;
import soft.edu.pojo.SchUniAndMaj;
import soft.edu.pojo.SchUniversity;
import soft.edu.service.SchUniversityService;

import java.util.List;

@Service("schUniversityService")
public class SchUniversityServiceImpl implements SchUniversityService {

    @Autowired
    private SchUniversityMapper schUniversityMapper;

//    获取所有院校信息
    @Override
    public ServerResponse<List<SchUniversity>> getAll() {
        List<SchUniversity> listSchUniversity = schUniversityMapper.getAll();
        if(listSchUniversity.isEmpty()){
            return ServerResponse.createByError("院校信息查询不到");
        }else {
            return ServerResponse.createBySuccess("院校信息查询成功",listSchUniversity);
        }
    }

//    根据搜索框查找信息
    @Override
    public ServerResponse<List<SchUniversity>> getAllbySearch(String keywords) {
        List<SchUniversity> listSchUniversity = schUniversityMapper.getAllbySearch(keywords);
        if(listSchUniversity.isEmpty()){
            return ServerResponse.createByError("院校信息搜索框查询不到");
        }else {
            return ServerResponse.createBySuccess("院校信息搜索框查询成功",listSchUniversity);
        }
    }

    //根据条件筛选信息
    @Override
    public ServerResponse<List<SchUniversity>> getAllbyFiltrate(
            String city, String is_211, String is_985, String is_graduate_school,
            String is_self_line) {
        if(city==null||city.equals("")){
            city = "%%";
        }
        List<SchUniversity> listSchUniversity = schUniversityMapper.getAllbyFiltrate(
                city, is_211, is_985, is_graduate_school, is_self_line);
        if(listSchUniversity.isEmpty()){
            return ServerResponse.createByError("根据条件查询学校失败");
        }else {
            return ServerResponse.createBySuccess("根据条件查询学校成功",listSchUniversity);
        }

    }

//    返回根据专业检索后的院校信息
    @Override
    public ServerResponse<List<SchUniAndMaj>> getInfoByUniAndMaj(String maj_name) {
        List<SchUniAndMaj> listSchUniAndMaj =
                schUniversityMapper.getInfoByUniAndMaj(maj_name);
        if(listSchUniAndMaj.isEmpty()){
            return ServerResponse.createByError("根据专业检索院校信息失败");
        }else {
            return ServerResponse.createBySuccess(
                    "根据专业检索院校信息成功",listSchUniAndMaj);
        }
    }
}
